package com.metaera.app.ui.fragments;

import android.os.Bundle;
import android.view.View;

import com.lxj.xpopup.XPopup;
import com.metaera.app.R;
import com.metaera.app.controller.presenter.CategoryPresenter;
import com.metaera.app.controller.view.FlashNewsCategoryView;
import com.metaera.app.ui.core.BaseFragment;
import com.metaera.app.ui.popup.FlashNewsCategoryPopup;

import net.lucode.hackware.magicindicator.MagicIndicator;

import androidx.viewpager.widget.ViewPager;

/**
 * 快讯，具体的分类内容
 */
public class FlashNewsTypeFragment extends BaseFragment {

    private ViewPager      mViewPager;
    private View           mImageViewMenu;
    private MagicIndicator mMagicIndicator;

    private FlashNewsCategoryPopup mCategoryPopup;


    @Override
    protected int getLayoutId() {

        return R.layout.fragment_flash_news_type;
    }

    @Override
    protected void initialize(Bundle savedInstanceState) {
        mViewPager = findViewById(R.id.view_pager);
        mImageViewMenu = findViewById(R.id.image_view_menu);
        mMagicIndicator = findViewById(R.id.magic_indicator);

        // init
        mCategoryPopup = new FlashNewsCategoryPopup(mViewPager.getContext(), mViewPager);

        // 初始化点击
        mImageViewMenu.setOnClickListener(v ->
                new XPopup.Builder(v.getContext()).enableDrag(false).asCustom(mCategoryPopup).show());

        // network
        CategoryPresenter categoryPresenter = new CategoryPresenter();
        categoryPresenter.setModelAndView(new FlashNewsCategoryView(getChildFragmentManager(),
                mViewPager, mMagicIndicator));
        categoryPresenter.flashNews();
    }

}
